package com.datastructure.test.reversesentence;

public class ReverseSentence {

    public static void main(String[] args) {

    }

    public String ReverseSentence(String str) {
        String[] split = str.split(" ");
        int length = split.length;
        int mid = length /2;
        for (int i = 0; i < mid; i++) {
            swap(split,i, length -i-1);
        }
        return String.join(" ",split);
    }

    private void swap(String[] split, int i, int j) {
        String temp = split[i];
        split[i]=split[j];
        split[j]=temp;
    }
}
